// import request from 'umi-request';
import { message } from 'antd';
import { extend } from 'umi-request';

const request = extend({
  timeout: 1000,
  headers: {
    'Content-Type': 'application/json',
  },
  params: {
    token: localStorage.getItem('token') || undefined,
  },
  data: {
    token: localStorage.getItem('token') || undefined,
  },
});

// request.interceptors.request.use((url, options) => {
//   console.log(options);
//   return {
//     url: url,
//     options: {
//       ...options,
//       parmas: { ...options.params, token: localStorage.getItem('token') },
//     },
//   };
// });

const http = {
  get(url: string, params?: object) {
    return request.get(url, { params: params }).then((response) => {
      return response;
    });
  },
  post(url: string, data?: object) {
    return request
      .post(url, {
        data: data,
      })
      .then((response) => {
        if (response.status === 0) {
          return response;
        } else {
          message.error(response.msg);
        }
      });
  },
};

export default http;
